package com.cskaoyan.controller;

import com.cskaoyan.bean.data.UserIndexData;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Pudding
 * @Date 2024/6/14 20:00
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {

    @Autowired
    OrderService orderService;

    //1. 根据用户id查询用户首页信息
    @RequestMapping("index")
    public BaseRespVo index(){
        //1.1 获取用户id
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()){
            Integer userId = (Integer) subject.getPrincipal();
            //1.2 根据用户id查询用户首页信息
            UserIndexData data = orderService.userIndex(userId);
            return BaseRespVo.ok(data);
        }else {
            return BaseRespVo.unAuthc();
        }
    }
}
